<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next" ></script>
</head>
<body>
    <div id="app"></div>
    
</body>
<script>
    const app=Vue.createApp({ 
        data(){
            return{
                arr:['张三','李四','王五'],
                obj:{
                    one:'zhang',
                    two:'li',
                    three:'wang'
                }
            }
        },
        methods:{
            btnclick(){
                this.arr.push('jspang')
            }
        },
        //v-for循环如果有任意值改变，那么整个列表都会重新渲染
        //所以可以在v-for后面绑定一个key值（需要有唯一性
        //这样在循环的时候只会重新渲染改变的量

        //数组和对象的循环不太一样
        template:`
            <ul>
                <li v-for="(item,index) in arr" :key='key'>[{{index}}]{{item}}</li>
            </ul>
            <button @click='btnclick'>点击添加</button>
            <ul>
                <li v-for="(value,key,index) in obj">[{{index}}]{{key}}-{{value}}</li>
            </ul>
        `

    }) 
    const vm=app.mount("#app")
</script>
</html>